package com.ptu.spzx.manager.controller;

import com.github.pagehelper.PageInfo;
import com.ptu.spzx.manager.service.CourseUserService;
import com.ptu.spzx.manager.service.SysUserService;
import com.ptu.spzx.model.dto.system.*;
import com.ptu.spzx.model.entity.system.SysUser;
import com.ptu.spzx.model.vo.common.Result;
import com.ptu.spzx.model.vo.common.ResultCodeEnum;
import java.util.*;

import com.ptu.spzx.model.vo.system.SysUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/ac/system/sysUser")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private CourseUserService courseUserService;

    //1 用户条件分页查询接口
    @GetMapping(value = "/findByPage/{pageNum}/{pageSize}")
    public Result findByPage(@PathVariable("pageNum") Integer pageNum,
                             @PathVariable("pageSize") Integer pageSize,
                             SysUserDto sysUserDto) {
        PageInfo<SysUser> pageInfo = sysUserService.findByPage(pageNum,pageSize,sysUserDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    //用户添加
    @PostMapping(value = "/saveSysUser")
    public Result saveSysUser(@RequestBody SysUserDeptDto sysUserDeptDto){
        sysUserService.saveSysUser(sysUserDeptDto);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //用户修改
    @PutMapping(value = "/updateSysUser")
    public Result updateSysUser(@RequestBody SysUser sysUser){
        sysUserService.updateSysUser(sysUser);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //用户删除
    @DeleteMapping(value = "/deleteById/{userId}")
    public Result deleteById(@PathVariable("userId") List<Long> userId){
        sysUserService.deleteById(userId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //用户分配角色
    //保持分配数据
    @PostMapping("/doAssign")
    public Result doAssign(@RequestBody AssginRoleDto assginRoleDto){
        sysUserService.doAssign(assginRoleDto);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
    //远程调用接口
    @GetMapping("/setClassId/{stuIds}")
    public Result setClassId(@PathVariable("stuIds") List<String> stuIds,@RequestParam(value = "className") String className){
        sysUserService.setClassId(stuIds,className);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/getStu/{stuId}")
    public SysUser getStu(@PathVariable("stuId") String stuId){
        SysUser userInfo=sysUserService.getStu(stuId);
        return userInfo;
    }

    @GetMapping("/getStuList")
    public List<SysUser> getStuList(@RequestParam("className") String className){
        List<SysUser> userInfo=sysUserService.getStuList(className);
        return userInfo;
    }

    @GetMapping("/getStuListByClass")
    public List<String> getStuListByClass(@RequestParam("className") String className){
        List<String> stuIds=sysUserService.getStuListByClass(className);
        return stuIds;
    }

    @GetMapping("/setClassNull")
    public Result setClassNull(@RequestParam("className") String className){
        sysUserService.setClaaNull(className);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/getStuListByClassName/{pageNum}/{pageSize}")
    public PageInfo<SysUser> getStuListByClassName(@RequestParam("classNames") List<String> classNames
            ,@PathVariable("pageNum") Integer pageNum,
                                                   @PathVariable("pageSize")Integer pageSize){
        PageInfo<SysUser> stu=sysUserService.getStuListByClassName(classNames,pageNum,pageSize);
        return stu;
    }

    //设置课程教师
    @GetMapping("/addCourseUser")
    public Result addCourseUser(@RequestParam(value = "teachIds") List<Long> teachIds,@RequestParam Long courseId){
        courseUserService.addCourseUser(teachIds,courseId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/deleteCourseUser")
    public Result deleteCourseUser(@RequestParam Long curseId){
        courseUserService.deleteCourseUser(curseId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/selectCourseIdByteachId")
    public List<Long> selectCourseIdByteachId(@RequestParam Long teachId){
        List<Long> courseIds= courseUserService.selectCourseIdByteachId(teachId);
        return courseIds;
    }

    @GetMapping("/selectTeacherIdByCourseId")
    public List<Long> selectTeacherIdByCourseId(@RequestParam Long courseId){
        List<Long> teacherIds=courseUserService.selectTeacherIdByCourseId(courseId);
        return teacherIds;
    }

    @GetMapping("/getStuListByStuIds")
    public List<SysUser> getStuListByAllStuId(@RequestParam("stuIds") List<String> stuIds){
        List<SysUser> userInfos=sysUserService.getStuListByAllClassName(stuIds);
        return userInfos;
    }

    @GetMapping("/getStuInfo")
    public SysUser getStuInfo(@RequestParam("userName") String userName){
        SysUser userInfo=sysUserService.getStuInfo(userName);
        return userInfo;
    }


}
